home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 322 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  5.6 KB

  1. From: Eugene Lazutkin <eugene@int.com>
  2. Message-ID: <01BAF61B.3131B100@dino.int.com>
  3. X-Original-Date: Thu, 8 Feb 1996 11:47:08 -0600
  4. Path: in1.uu.net!bounce-back
  5. Date: 08 Feb 96 17:55:57 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Organization: -
  8. Newsgroups: comp.std.c++
  9. Subject: Portability. Modules. WAS: RE:  Are all Windows programs ill-formed?
  10. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  11.     iQBFAgUBMRo59eEDnX0m9pzZAQE8ewGAkeCu5skxbsEhGSB3nhMK3T3feoG0TH6r
  12.     M1OYzco+hEBeTk6jCB0h30aOEYTm25VR
  13.     =CNUC
  14.  
  15. On     Tuesday, February 06, 1996 9:18 PM, 
  16. rich@kastle.com (Richard Krehbiel) wrote:
  17. > fjh@munta.cs.mu.OZ.AU (Fergus Henderson) wrote:
  18. > >I did not claim that any or all Windows compilers were not conforming.
  19. > >I simply pointed out what they were required to do in order to conform.
  20. > >I did say that
  21. > >| I think the problem is due to Microsoft overlooking the C and C++
  22. > >| standards, not vice versa.
  23. > >but the problem I was referring to was not that Microsoft's compilers
  24. > >don't conform to the standard (most likely they do) but rather that
  25. > >Microsoft encourages people to write non-portable, non-standard-conforming
  26. > >code which is then subject to the usual problems of vendor lock-in.
  27. > YES, YES, YES.  This is IT.
  28.  
  29. If you use Windows GUI => your program is non-portable by definition, 
  30. because your use vendor-specific libraries.  Under these circumstances 
  31. I personally don't care about portability and how my main function looks 
  32. like.
  33.  
  34. This is not a matter of a portability! If you don't have a portable library 
  35. (GUI, math, network & Co.), your program will be non-portable anyway.
  36.  
  37. Current (and future :-( ) standard doesn't cover a very important topic: 
  38. libraries.  A library is not a bunch of somehow related (or unrelated) 
  39. functions. Sometimes you need initialize your library and clean up after 
  40. termination.  Shared libraries raise more complex questions.  Of course, 
  41. I want to enjoy the benefits of DLLs (dynamic link libraries). In this case 
  42. my library will be Windows-specific.
  43.  
  44. If I want to write a portable program in Windows, I write console-mode
  45. program (without any GUI) and use just standard iostream.h for an
  46. interaction with a user. It is a portable way, but usually it is not
  47. suitable for end users.
  48.  
  49. About the main() function.  A Windows compiler (MS, Borland, Symantec,
  50. Watcom) doesn't check its presence. Linker does. It knows the name of
  51. an entry point.  Standard library contains some sort of proxy with this
  52. name which calls main() or whatever. So it is a matter of a proxy for a
  53. linker.  You may think that main() is buried in the standard Windows
  54. library and it will call WinMain(). That's it, you use the main()
  55. implicitly.
  56.  
  57. BTW, the same can be applied to the Unix (MacOS) platform.  X-based
  58. (Motif-based, Fresco-based,...) program are not portable either unless
  59. you have the specific GUI implementation for your target platforms.
  60.  
  61. Another point of non-portability is #pragmas.  Static containers are
  62. almost useless unless you can specify the order of their
  63. construction/destruction.  Borland provides you with #pragma
  64. startup/exit (am I correct with names?). With this tool you can specify
  65. a priority. It is not a ultimate medicine but it helps a lot!
  66.  
  67. If you use a static container with some statically included items (by
  68. their constructors), your objects will be well-formed automatically in
  69. most cases (I mean practical cases):
  70.  
  71. static Container  list(); // The constructor of this list has higher priority 
  72.               // than item's constructor. You do this trick
  73.               // with a #pragma.
  74. static Item    item1( list );    // All items are located in different files.
  75. static Item    item2( list );    // The item's constructor includes an item
  76.                 // into a list.
  77. /* ... */
  78. static Item    itemN( list );
  79.  
  80. // file with the main() function
  81. void    main() {                
  82.     /* ... */
  83.     // lets check all items
  84.     CHECK_ALL_ITEMS( list );
  85.     /* ... */
  86. }
  87.  
  88. Alternative way: include all items into the container manually and
  89. don't forget to do this initialization every time when you use this
  90. container in your program.
  91.  
  92. static Container  list();
  93.  
  94. static Item    item1();    // All items are located in different files.
  95. static Item    item2();
  96. /* ... */
  97. static Item    itemN();
  98.  
  99. // file with the main() function
  100. // you have to include here the declarations of all items!
  101. void    main() {                
  102.     /* ... */
  103.     // initialization of list, all items should be visible here! 
  104.     list.include( item1 );
  105.     list.include( item2 );
  106.     /* ... other includes ... */
  107.     list.include( itemN );
  108.     /* ... */
  109.     // lets check all items
  110.     CHECK_ALL_ITEMS( list );
  111.     /* ... */
  112. }
  113.  
  114. If you add a new item, you should add one more file in 1st case.  In
  115. 2nd case you have to modify several places in your program. And this is
  116. a potential source of errors.
  117.  
  118. Of course, this is just an example, but this is a real-live example. I
  119. meet these cases every my project.
  120.  
  121. I don't think that WinMain() is a serious source of incompatibility and
  122. non-portability.  I think that the main source is vendor-specific
  123. libraries (we can't do anything with that) and the obvious weakness of
  124. C++ standard in the modularization of programs. We don't have the
  125. strong definition of the module, how it can be controlled by us
  126. programmers (initialization, deinitialization, reusing by different
  127. threads and/or programs) and how we can create well-formed static
  128. structures and conglomerates.
  129.  
  130. If we don't solve these problems, we will have non-portable
  131. applications. This is not a just language level.  This is a level ov
  132. C++ machine, how it works, C++ environment.
  133.  
  134. Thanks for patience
  135.  
  136.  
  137. Eugene Lazutkin
  138. eugene@int.com
  139. ---
  140. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  141.   Contact address: std-c++-request@ncar.ucar.edu.  Moderation policy:
  142.   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
  143.